package com.longjianghuasheng.logistics.business.mine.viewmodel

import androidx.databinding.ObservableField
import androidx.lifecycle.MutableLiveData
import com.longjianghuasheng.logistics.base.BaseMultiStateViewModel
import com.longjianghuasheng.logistics.data.model.bean.ApiResponseNoData
import com.longjianghuasheng.logistics.ext.commit2
import com.longjianghuasheng.logistics.ext.toastNormal
import com.longjianghuasheng.logistics.network.apiService

class ChangePasswordViewModel : BaseMultiStateViewModel() {

    val notify by lazy {
        MutableLiveData<ApiResponseNoData>()
    }


    val oldPasswordObservableField by lazy {
        ObservableField("")
    }
    val passwordObservableField by lazy {
        ObservableField("")
    }
    val rePasswordObservableField by lazy {
        ObservableField("")
    }

    fun change_password() {
        val old_password = oldPasswordObservableField.get()
        val password = passwordObservableField.get()
        val repassword = rePasswordObservableField.get()

        if (old_password.isNullOrBlank()) {
            toastNormal("请输入原密码")
            return
        }
        if (password.isNullOrBlank()) {
            toastNormal("请输入新密码")
            return
        }
        if (repassword.isNullOrBlank()) {
            toastNormal("请再次输入新密码")
            return
        }

        if (password != repassword) {
            toastNormal("两次输入的密码不一致")
            return
        }


        commit2({ apiService.change_password(old_password, password, repassword) }, notify)

    }
}